<template>
	<view class="u-p-l-14 u-p-r-14 bg-white">
		<u-form :model="form" ref="form1" label-width="auto" :border-bottom="false">
			<u-form-item label="自动营业或打样">
				<template #right>
					<u-switch v-model="form.autoOpen"></u-switch>
				</template>
			</u-form-item>

			<u-form-item label="支付后自动打印">
				<template #right>
					<u-switch v-model="form.autoPrint"></u-switch>
				</template>
			</u-form-item>

			<u-form-item label="接单后自动打印">
				<template #right>
					<u-switch v-model="form.autoAcceptPrint"></u-switch>
				</template>
			</u-form-item>

			<u-form-item label="打印模板类型">
				<template #right>
					<!-- <u-switch></u-switch> -->
					<u-radio-group v-model="form.printModel" active-color="#ffc300">
						<u-radio :name="1">有价格</u-radio>
						<u-radio :name="2">无价格</u-radio>
					</u-radio-group>

				</template>
			</u-form-item>

			<u-form-item label="自动接单">
				<template #right>
					<u-switch v-model="form.autoAccept"></u-switch>
				</template>
			</u-form-item>

		</u-form>

		<view class="btnwrap">
			<u-button type="warning" @click="submit">确定</u-button>
		</view>

	</view>
</template>

<script setup lang="ts">
	import shopApi from '@/api/shop'
	import { reactive } from "vue";
	import { onLoad } from '@dcloudio/uni-app'
	import shop from '@/api/shop';

	onLoad(() => {
		shopApi.getShopDetal().then(res => {
			Object.assign(form, res.data)
		})
	})

	const form = reactive({
		type:1,
		autoOpen: 0,//自动营业或打样
		autoPrint: 0,//支付后自动打印
		autoAcceptPrint: 0,//接单后是否自动打印
		printModel: 0,//打印模板类型
		autoAccept: 0,//是否自动接单
	})

	function submit() {
		uni.showLoading({
			title: '加载中...'
		})

		shopApi.checkOutPri().then(res => {
			if (res.data === 1) {

				form.autoOpen = Number(form.autoOpen)
				form.autoPrint = Number(form.autoPrint)
				form.autoAcceptPrint = Number(form.autoAcceptPrint)
				form.autoAccept = Number(form.autoAccept)

				return shopApi.setPortinfo(form)
			} else {
				uni.showToast({
					title: '请先添加打印机',
					icon: 'none'
				})
			}
		}).then(res=>{
			uni.showToast({
				title:res.msg
			})
		})
	}
</script>

<style lang="scss" scoped>
	.btnwrap {
		padding-top: 120upx;
	}
</style>
